<?php

$case_num = $this->caseInfo ['FDMS_case_num'];
$notesHREF = "<A href=\"javascript:openCaseNotesWindow('$case_num')\" class=\"menuLinks\">Notes</A>";

$saveandcloseURL = "/index/vassaveandexit";

$saveandcloseHREF = "<a class=\"menuLinks\" href='$saveandcloseURL'>Save and Exit</a>";

$funeralHomeName = $this->caseFHinfo ['name'];
$funeralHomeAddr = $this->caseFHinfo ['addr1'];
$funeralHomeCity = $this->caseFHinfo ['city'];
$funeralHomeState = $this->caseFHinfo ['state'];
$funeralHomeZip = $this->caseFHinfo ['zip'];
$funeralHomePhone = $this->caseFHinfo ['phone'];
$funeralHomeFax = $this->caseFHinfo ['fax'];
$funeralHomePicture = $this->caseFHinfo ['photo_image'];
$funeralHomeLogo = $this->caseFHinfo ['logo_image'];

$urlBAR = "$notesHREF | $saveandcloseHREF";
$num_cart_items = 0;

if (! isset ( $this->hide_breadcrumbs ))
	$this->hide_breadcrumbs = false;
if (! isset ( $this->change_next_button ))
	$this->change_next_button = false;
if (! isset ( $this->hide_back_button ))
	$this->hide_back_button = false;

$this->case_num = $this->caseInfo ["FDMS_case_num"];

# Edd - this lets you know when to show/hide the breadcrumbs
$hideBreadCrumbs = false;
if ($this->currentVASpage == "EXPECT" || $this->currentVASpage == "LIFE")
	$hideBreadCrumbs = true;

$this->crumbs = "";
if ($this->breadcrumbs) {
	foreach ( $this->breadcrumbs as $crumb ) {
		$url = $crumb ['url'];
		$title = $crumb ['label'];
		$this->crumbs .= "<a href=\"$url\">$title</a><br>";
	}
}

if ($this->currentVASpage == "CHOICES") {
	// take choices and generate Dojo stack container for it? not needed, the view script will
// handle that.
} else if ($this->currentVASpage == "MERCHANDISE") {
	// best way to do this is ...
	// $this->catalog ---> $catalog_items_str
	$catalog_items = array ();
	foreach ( $this->catalog as $catalog_item ) {
		$FDMS_id = $catalog_item ['price_list_id'];
		$cl = $catalog_item ['line_number'];
		$descr = addslashes ( stripslashes ( $catalog_item ['item_description'] ) );
		$price = $catalog_item ['item_amount'];
		$category = $catalog_item ['item_category'];
		
		$item_str = "{";
		$item_str .= "id:$FDMS_id, ";
		$item_str .= "cl:'$cl', ";
		$item_str .= "category:'$category', ";
		$item_str .= "name:'$descr', ";
		$item_str .= "price:$price ";
		$item_str .= "}";
		
		$catalog_items [] = $item_str;
	}
	$catalog_items_str = implode ( ", ", $catalog_items );
	
	$catalog_layout [] = "{ field: 'id', name: 'Price List ID', width:'90px', hidden:true }";
	$catalog_layout [] = "{ field: 'cl', name: 'CL#', width:'40px' }";
	$catalog_layout [] = "{ field: 'category', name: 'Category', width:'80px', hidden:true }";
	$catalog_layout [] = "{ field: 'name', name: 'Item Name', width:'auto' }";
	$catalog_layout [] = "{ field: 'price', name: '$ Amount', width:'80px', formatter:priceFormatter, 
        	styles:'text-align:right;' }";
	$catalog_layout_str = implode ( ", ", $catalog_layout );
	
	$catalog_query_str = "id: '*'";
	
	// $this->cart ----> $cart_items_str
	$num_cart_items = 1;
	$cart_items = array ();
	foreach ( $this->cart as $cart_item ) {
		// cart item fields:
		// id (hidden), price_list_id, description, price, qty, total, source
		$id = $cart_item ['price_list_id'];
		$cl = $cart_item ['line_number'];
		$item_name = $cart_item ['item_description'];
		$item_price = 1.0 * $cart_item ['item_amount'];
		$qty = $cart_item ['qty'];
		$item_total = $item_price * $qty;
		$item_purchase_type = $cart_item ['source'];
		$item_category = $cart_item ['item_category'];
		$item_str = "{";
		$item_str .= "idx:$num_cart_items, ";
		$item_str .= "id:$id, ";
		$item_str .= "cl:$cl, ";
		$item_str .= "category:'$item_category', ";
		$item_str .= "name:'$item_name', ";
		$item_str .= "price:$item_price, ";
		$item_str .= "qty:$qty, ";
		$item_str .= "total:$item_total, ";
		$item_str .= "type:'$item_purchase_type' ";
		$item_str .= "}";
		$cart_items [] = $item_str;
		$num_cart_items ++;
	}
	$cart_items_str = implode ( ", ", $cart_items );
	$cart_layout [] = "{ field: 'idx', name: 'IDx', width:'80px', hidden:true }";
	$cart_layout [] = "{ field: 'id', name: 'ID', width:'80px', hidden:true }";
	$cart_layout [] = "{ field: 'cl', name: 'CL#', width:'40px' }";
	$cart_layout [] = "{ field: 'name', name: 'Item Name', width:'auto' }";
	$cart_layout [] = "{ field: 'price', name: 'Price', width:'80px', editable:'true', formatter:priceFormatter, styles:'text-align:right;' }";
	$cart_layout [] = "{ field: 'qty', name: 'Quantity', width:'80px', editable:'true', styles:'text-align:right' }";
	$cart_layout [] = "{ field: 'total', name: 'Total', width:'80px', formatter:priceFormatter, styles:'text-align:right;' }";
	$cart_layout [] = "{ field: 'type', name: 'Source', width:'auto' }";
	$cart_layout_str = implode ( ", ", $cart_layout );
	
	$cart_query_str = "idx: '*'";
} else if ($this->currentVASpage == "SERVICES") {
	// $this->catalog ---> $catalog_items_str
	$catalog_items = array ();
	foreach ( $this->catalog as $catalog_item ) {
		$FDMS_id = $catalog_item ['price_list_id'];
		$name = $catalog_item ['item_name'];
		$descr = $catalog_item ['item_description'];
		$price = $catalog_item ['item_amount'];
		$category = $catalog_item ['item_category'];
		$line_num = $catalog_item ['line_number'];
		
		$item_str = "{";
		$item_str .= "id:$FDMS_id, ";
		$item_str .= "cl:$line_num, ";
		$item_str .= "category:'$category', ";
		$item_str .= "name:'$descr', ";
		$item_str .= "price:$price ";
		$item_str .= "}";
		
		$catalog_items [] = $item_str;
	}
	$catalog_items_str = implode ( ", ", $catalog_items );
	
	$catalog_layout [] = "{ field: 'id', name: 'FDMS#', width:'50px', hidden:true }";
	$catalog_layout [] = "{ field: 'category', name: 'Category', width:'80px', hidden:true }";
	$catalog_layout [] = "{ field: 'cl', name: 'CL#', width:'30px' }";
	$catalog_layout [] = "{ field: 'name', name: 'Description', width:'auto' }";
	$catalog_layout [] = "{ field: 'price', name: 'Item Price', width:'80px', 
        	formatter:priceFormatter, 
        	styles:'text-align:right;' }";
	$catalog_layout_str = implode ( ", ", $catalog_layout );
	
	$catalog_query_str = "id: '*'";
	
	// $this->cart ----> $cart_items_str
	$num_cart_items = 1;
	$cart_items = array ();
	foreach ( $this->cart as $cart_item ) {
		// cart item fields:
		// id (hidden), price_list_id, description, price, qty, total, source
		$id = $cart_item ['price_list_id'];
		$item_name = $cart_item ['item_description'];
		$item_price = 1.0 * $cart_item ['item_amount'];
		$item_qty = 1.0;
		$item_total = $item_price * 1.0;
		$item_purchase_type = $cart_item ['source'];
		$item_category = $cart_item ['item_category'];
		$item_line_num = $cart_item ['line_number'];
		
		$item_str = "{";
		$item_str .= "idx:$num_cart_items, ";
		$item_str .= "id:$id, ";
		$item_str .= "cl:$item_line_num, ";
		$item_str .= "category:'$item_category', ";
		$item_str .= "name:'$item_name', ";
		$item_str .= "price:$item_price, ";
		$item_str .= "qty:$item_qty, ";
		$item_str .= "total:$item_total, ";
		$item_str .= "type:'$item_purchase_type' ";
		$item_str .= "}";
		$cart_items [] = $item_str;
		$num_cart_items ++;
	}
	
	$cart_items_str = implode ( ", ", $cart_items );
	
	$cart_layout [] = "{ field: 'idx', name: 'IDx', width:'80px', hidden:true }";
	$cart_layout [] = "{ field: 'cl', name: 'CL#', width:'30px', editable:true }";
	$cart_layout [] = "{ field: 'id', name: 'FDMS#', width:'50px', hidden:true }";
	$cart_layout [] = "{ field: 'name', name: 'Item Name', width:'auto' }";
	$cart_layout [] = "{ field: 'qty', name: 'Number', width:'50px', editable:true, styles:'text-align:right;' }";
	$cart_layout [] = "{ field: 'price', name: 'Cost', width:'50px', editable:true, formatter:priceFormatter, styles:'text-align:right;' }";
	$cart_layout [] = "{ field: 'total', name: 'Total', width:'70px', hidden:true }";
	$cart_layout [] = "{ field: 'type', name: 'Source', width:'auto' }";
	$cart_layout_str = implode ( ", ", $cart_layout );
	
	$cart_query_str = "idx: '*'";
} else if ($this->currentVASpage == "CASHADV") {
	// $this->catalog ---> $catalog_items_str
	$catalog_items = array ();
	foreach ( $this->catalog as $catalog_item ) {
		$idx = $catalog_item ['id'];
		$FDMS_id = $catalog_item ['price_list_id'];
		$descr = addslashes ( stripslashes ( $catalog_item ['item_description'] ) );
		$price = $catalog_item ['item_amount'];
		$category = $catalog_item ['item_category'];
		$line_number = $catalog_item ['line_number'];
		
		$item_str = "{";
		$item_str .= "id:$idx, ";
		$item_str .= "cl:$line_number, ";
		$item_str .= "category:\"$category\", ";
		$item_str .= "name:'$descr', ";
		$item_str .= "price:$price ";
		$item_str .= "}";
		
		$catalog_items [] = $item_str;
	}
	$catalog_items_str = implode ( ",\n ", $catalog_items );
	
	$catalog_layout [] = "{ field: 'id', name: 'Price List ID', width:'90px', hidden:true }";
	$catalog_layout [] = "{ field: 'category', name: 'Category', width:'80px', hidden:true }";
	$catalog_layout [] = "{ field: 'cl', name: 'CL#', width:'30px' }";
	$catalog_layout [] = "{ field: 'name', name: 'Item Name', width:'auto' }";
	$catalog_layout [] = "{ field: 'price', name: 'Item Price', width:'80px', formatter:priceFormatter, styles:'text-align:right;' }";
	$catalog_layout_str = implode ( ", ", $catalog_layout );
	
	$catalog_query_str = "id: '*'";
	
	// $this->cart ----> $cart_items_str
	$num_cart_items = 1;
	$cart_items = array ();
	foreach ( $this->cart as $cart_item ) {
		// cart item fields:
		// id (hidden), price_list_id, description, price, qty, total, source
		$id = $cart_item ['price_list_id'];
		$item_name = addslashes ( stripslashes ( $cart_item ['item_description'] ) );
		$item_price = $cart_item ['item_amount'];
		$item_qty = $cart_item ['qty'];
		$item_total = $cart_item ['total'];
		;
		$item_purchase_type = $cart_item ['source'];
		$item_category = $cart_item ['item_category'];
		$cl = $cart_item ['line_number'];
		
		$item_str = "{";
		$item_str .= "idx:$num_cart_items, ";
		$item_str .= "id:$id, ";
		$item_str .= "cl:$cl, ";
		$item_str .= "category:'$item_category', ";
		$item_str .= "name:'$item_name', ";
		$item_str .= "price:$item_price, ";
		$item_str .= "qty:$item_qty, ";
		$item_str .= "total:$item_total, ";
		$item_str .= "type:'$item_purchase_type' ";
		$item_str .= "}";
		$cart_items [] = $item_str;
		$num_cart_items ++;
	}
	
	$cart_items_str = implode ( ", ", $cart_items );
	
	$cart_layout [] = "{ field: 'idx', name: 'IDx', width:'80px', hidden:true }";
	$cart_layout [] = "{ field: 'id', name: 'Price List ID', width:'90px', hidden:true }";
	$cart_layout [] = "{ field: 'cl', name: 'CL#', width:'30px', editable:true }";
	$cart_layout [] = "{ field: 'name', name: 'Item Name', width:'auto' }";
	$cart_layout [] = "{ field: 'price', name: 'Price', width:'80px', editable:true, formatter:priceFormatter, styles:'text-align:right;' }";
	$cart_layout [] = "{ field: 'qty', name: 'Qty', width:'40px', editable:true }";
	$cart_layout [] = "{ field: 'total', name: '$ Total', width:'70px', formatter:priceFormatter, styles:'text-align:right;' }";
	$cart_layout [] = "{ field: 'type', name: 'Source', width:'auto' }";
	$cart_layout_str = implode ( ", ", $cart_layout );
	
	$cart_query_str = "idx: '*'";

} else {
	$catalog_items_str = "";
	$catalog_query_str = "";
	$catalog_layout_str = "";
	$cart_items_str = "";
	$cart_query_str = "";
	$cart_layout_str = "";
}
?>
<?php

echo $this->doctype ( Zend_View_Helper_Doctype::XHTML1_TRANSITIONAL ) . "\n";
?>
<html>
<head>

  <?php
		echo $this->headTitle ( 'Keystone Virtual Arrangement System' );
		?>

	<style type="text/css">
@import "/js/dijit/themes/tundra/tundra.css";

@import "/js/dojox/grid/resources/tundraGrid.css";

@import "/js/dojox/form/resources/DropDownSelect.css";

/*@import "/css/keystoneadmin.css";*/
@import "/css/vascore.css";

@import "/css/sidebar.css";
</style>
<link href="/css/print.css" type="text/css" rel="stylesheet"
	media="print">

<SCRIPT language="JavaScript1.2">
	function formatPrice(price) { return '$'+price; }
	function priceFormatter(price) {
		var sprice = price.toString();
		var x = sprice.split('.');
		var dollars, cents;
		
		dollars = x[0];
		if(x.length>1)
			cents = x[1];
		else
			cents = 0;
			
		var j = 0;
		var dollars_formatted = '';
		
		var i = 0;
		for( j=dollars.length-1; j >= 0; j--, i++ )
		{
			if( i>0 && (i%3)==0)
				dollars_formatted = ',' + dollars_formatted;
			dollars_formatted = dollars.substr(j,1) + dollars_formatted;
		}			
		
		if(cents.length==1) cents = '0'+cents;
		return '$'+dollars_formatted;	
	}
		
	function priceFormatter2(price) {
		var sprice = price.toString();
		var x = sprice.split('.');
		var dollars, cents;
		
		dollars = x[0];
		if(x.length>1)
			cents = x[1];
		else
			cents = 0;
			
		var j = 0;
		var dollars_formatted = '';
		
		var i = 0;
		for( j=dollars.length-1; j >= 0; j--, i++ )
		{
			if( i>0 && (i%3)==0)
				dollars_formatted = ',' + dollars_formatted;
			dollars_formatted = dollars.substr(j,1) + dollars_formatted;
		}			
		
		if(cents.length==1) cents = '0'+cents;
		return '$'+dollars_formatted+'.'+cents;
	}
	
	function openCaseNotesWindow(case_number)
	{
		var notes_window = window.open("/index/vasnotes/case_number/"+case_number,
		"noteswindow","menubar=0,resizable=0,width=400,height=350");
	}
	
	function closeCaseNotesWindow()
	{
		if(notes_window)
		{
			if(!notes_window.closed)
				notes_window.close();
		}
	}
	
	function updateFloralTotal()
	{
		//_floral_total
		var new_total_str = total_form.document.getElementById('newtotal').value;
		alert('new total is: ' + new_total_str);
	}
	
	function showFloralTotalForm()
	{
//		alert('attempting to show form');
		var line1 = '<html><body>New Total: <input type=text id="newtotal"><button onclick=\'updateFloralTotal()\'>Apply</button></body></html>';
		total_form = window.open("","traditional","title='New Total',menubar=0,resizable=0,width=300,height=250");		
		total_form.document.body.innerHTML = line1;
	}
	
	function closeFloralTotalForm()
	{
	}

	function hideTheNextButton()
	{
		document.getElementById('controlsnext').style.visibility = 'hidden';
	}

	function showTheNextButton()
	{
		document.getElementById('controlsnext').style.visibility = 'visible';
	}

	function jsVideoComplete( isComplete )
	{
		showTheNextButton();
	}
	
	function jsShowroomComplete( isComplete )
	{
		showTheNextButton();
	}
	
	// these two implement the popup window
	function openTributePointsWindow( tribute_type, bullet_points_ul )
	{
		if(tribute_type=='traditional')
		{
			trad_window = window.open("","traditional","menubar=0,resizable=0,width=520,height=480");
			if(trad_window) {
				trad_window.document.title = "Traditional Tribute";
				trad_window.document.body.innerHTML = bullet_points_ul;
			}
		}
		else
		if(tribute_type=='select')
		{
			var select_window = window.open("","select","menubar=0,resizable=0,width=520,height=480");
			if(select_window) {
				select_window.document.title = "Select Tribute";
				select_window.document.body.innerHTML = bullet_points_ul;
			}
		}
		else
		if(tribute_type=='basic')
		{
			var basic_window = window.open("","basic","menubar=0,resizable=0,width=520,height=480");
			if(basic_window) {
				basic_window.document.title = "Basic Tribute";
				basic_window.document.body.innerHTML = bullet_points_ul;
			}
		}
	}
	
	function closeTributePointsWindows( tribute )
	{
		if(trad_window)
		{
			if(!trad_window.closed)
				trad_window.close();
			trad_window = null;
		}
		if(select_window)
		{
			if(!select_window.closed)
				select_window.close();
			select_window = null;
		}
		if(basic_window)
		{
			if(!basic_window.closed)
				basic_window.close();
			basic_window = null;
		}
	}
	
	var startTime = -1;
	var finishTime = -1;
	var elapsedTime = 0;
	
   	djConfig = { isDebug: false, parseOnLoad:true };
    	var idx = <?php
					echo $num_cart_items?>;
    	var current_page = '<?php
					echo $this->currentVASpage?>';
    	var current_branch = <?php
					echo $this->caseInfo ['branch_num']?>;
    	var current_case = '<?php
					echo $this->caseInfo ['FDMS_case_num']?>';
    	var current_arranger = <?php
					echo $this->caseInfo ['FDMS_funeral_director_id']?>;
    	var current_locale = <?php
					echo $this->caseFHinfo ['locale_id']?>;
    	var current_region = '<?php
					echo $this->caseFHinfo ['region']?>';
    	
    	var startTime = -1;
    	var finishTime = -1;
    	var elapsedTime = -1;
	</SCRIPT>

	  <?php
			// grab the JS for this page
			$this->headScript ()->appendFile ( JS_BASE . "/dojo/dojo.js" );
			?>
   
   <script type="text/javascript">
   function gotoPreviousPage(currentpage)
   {
   		var prevpageurl = '/index/vasprevpage/current_page/'+currentpage;
//   		alert('going to '+prevpageurl);
		window.location = prevpageurl;
   }
   </script>

<script type="text/javascript">
   		var branch_num = <?php
					echo $this->caseFHinfo ['branch_number']?>;
   		var locale_id = <?php
					echo $this->caseFHinfo ['locale_id']?>;
   		var case_num = '<?php
					echo $this->case_num?>';
   		
   		var catalogArray =  {
            identifier: "id",
			label: 'id',
			items: [<?php
			echo $catalog_items_str;
			?>]
        };
   		var catalogQuery = { <?php
					echo $catalog_query_str;
					?> };
   		var catalogLayout = [ <?php
					echo $catalog_layout_str;
					?> ];
   		
   		var cartArray =  {
            identifier: "idx",
			label: 'idx',
			items: [<?php
			echo $cart_items_str;
			?>]
        };
        
   		var cartQuery = { <?php
					echo $cart_query_str;
					?> };
   		var cartLayout = [ <?php
					echo $cart_layout_str;
					?> ];
   </script>
      
   <?php
			
			if ($this->currentVASpage == "CATERING") {
				$caterer = addslashes ( stripslashes ( $this->caseInfo ['caterer'] ) );
				$menustr = addslashes ( stripslashes ( $this->caseInfo ['menu'] ) );
				list ( $menu, $price ) = explode ( ' : ', $menustr );
				
				$headcount = $this->caseInfo ['headcount'];
				if (empty ( $headcount ))
					$headcount = 0;
				
	// spit out a script segment containing the selected caterer, menu, headcount, price, and total
				echo "<script type=\"text/javascript\">\n";
				echo "var stored_caterer = '$caterer';";
				echo "var stored_menu = '$menu';";
				echo "var stored_headcount = $headcount;";
				echo "</script>\n";
				
				$this->headScript ()->appendFile ( JS_BASE . "/vascatering.js" );
			} else if ($this->currentVASpage == "FLORAL") {
				$florist = addslashes ( stripslashes ( $this->caseInfo ['florist'] ) );
				$arrangementsxml = addslashes ( stripslashes ( $this->caseInfo ['arrangement'] ) );
				$arrangements = simplexml_load_string ( $arrangementsxml );
				$arr_arr = array ();
				if (null != $arrangements) {
					foreach ( $arrangements->collection as $arrangement ) {
						$arr_arr [] = "'{$arrangement->name}'";
					}
				}
				// spit out a script segment containing the selected florist and arrangement
				echo "<script type=\"text/javascript\">\n";
				echo "var stored_florist = '$florist';";
				echo "var stored_collection = [";
				echo implode ( ',', $arr_arr );
				echo "];";
				echo "</script>\n";
				
				$this->headScript ()->appendFile ( JS_BASE . "/vasfloral.js" );
			} else if ($this->currentVASpage == "MERCHANDISE") {
				$this->headScript ()->appendFile ( JS_BASE . "/vasmerchandise.js" );
			} else if ($this->currentVASpage == "SERVICES") {
				$this->headScript ()->appendFile ( JS_BASE . "/vasservices.js" );
			} else if ($this->currentVASpage == "CASHADV") {
				$this->headScript ()->appendFile ( JS_BASE . "/vascashadvances.js" );
			} else if ($this->currentVASpage == "VITALS") {
				if ($this->head_links != null) {
					foreach ( $this->head_links as $script ) {
					
					}
				}
				
				if ($this->head_scripts != null) {
					foreach ( $this->head_scripts as $script ) {
					}
				}
			}
			
			echo $this->headScript ();
			
			// where did the timing scripts go?
			?>    
<?php

$handlers = "startTiming();";
$unloadhandlers = "finishTiming();";
if ($this->currentVASpage == "BURIAL") {
	$handlers = "tradbuttonstart();startTiming();";
	$unloadhandlers = "closeTributePointsWindows();finishTiming();";
} else if ($this->currentVASpage == "CREMATION") {
	$handlers = "tradbuttonstart();startTiming();";
	$unloadhandlers = "closeTributePointsWindows();finishTiming();";
} else if ($this->currentVASpage == "MEMORIAL") {
	$handlers = "tradbuttonstart();startTiming();";
	$unloadhandlers = "closeTributePointsWindows();finishTiming();";
} else if ($this->currentVASpage == "CHOICES") {
	$handlers = "burialbuttonclicked();startTiming();";
} else if ($this->currentVASpage == "EXPECT" || $this->currentVASpage == "LIFE") {
	$handlers = "hideTheNextButton(); startTiming();";
} else if ($this->currentVASpage == "CASKET" || $this->currentVASpage == "URN") {
	$handlers = "hideTheNextButton(); startTiming();";
}

//if(!$this->hide_back_button)
// 	$this->controls = "<div style=\"text-align:left\"><button type=button id=\"backbutton\" onclick='gotoPreviousPage(\"$this->currentVASpage\");return false;' >Back</button></div>";
//else
//	$this->controls = "";


//if($this->currentVASpage == "CHOICES")
//{
//	$this->controls .= "<div style=\"width:50%\">
//	<span id=\"controls\"><input type=\"submit\" value=\" Save and Continue \" id=\"controlssave\">
//	</span></div>";
//}
//else 
//{
//	if($this->change_next_button)
//		$button_title = "Return";
//	else
//		$button_title = " ";


//	$this->controls .= "<div style=\"width:50%\">
//	<span id=\"controls\"><input type=\"submit\" value=\" $button_title \" id=\"controlsnext\">
//	</span></div>";
//}
if (! $this->hide_back_button)
	$this->controls = "<div style=\"width:100%\"><span id=\"controls\"><button type=button id=\"backbutton\" onclick='gotoPreviousPage(\"$this->currentVASpage\");return false;' >&nbsp;</button>";
else
	$this->controls = "<div style=\"width:100%\"><span id=\"controls\">";

if ($this->currentVASpage == "CHOICES") {
	$this->controls .= "
		<input type=\"submit\" value=\" &nbsp; \" id=\"controlssave\">
		</span></div>";
} else {
	if ($this->change_next_button) {
		$button_id = "controlsreturn";
		$button_title = " ";
	} else {
		$button_id = "controlsnext";
		$button_title = " ";
	}
	
	$this->controls .= "
		<input type=\"submit\" value=\" $button_title \" id=\"$button_id\">
		</span></div>";
}
?>
<script type="text/javascript"
	src="<?php
	echo JS_BASE . "/datetimepicker_css.js"?>"></script>
<script type="text/javascript">
	var startDateTime = null;
	var finishDateTime = null;
	
        function onLoadHandler()
        {
          <?php
										echo $handlers?>
        }

		function onunloadHandler()
		{
		  <?php
				echo $unloadhandlers?>
		}
		
	function startTiming()
	{
		//alert('starting page timer');
		startDateTime = new Date();
		startTime = startDateTime.getTime();
	}
	
	function finishTiming()
	{
		finishDateTime = new Date();
		stopTime = finishDateTime.getTime();
               //alert('stopping page timer');
		//console.log('stopping page timer');
		writeTimingRecord();
	}

        function myTimingObject(cur_page, cur_branch, cur_case, cur_arranger, cur_locale, cur_region, cur_elapsed) {
 		this.page = cur_page;
		this.branch = cur_branch;
		this.caseNumber = cur_case;
		this.arranger = cur_arranger;
		this.locale = cur_locale;
		this.region = cur_region;
		this.elapsed = cur_elapsed;
        }

	function writeTimingRecord()
	{
//console.log('writeTimingRecord');
		elapsed_time = stopTime - startTime;
 		var timingObj = new myTimingObject( current_page, current_branch, current_case, current_arranger, current_locale, current_region, elapsed_time );
		
		//console.log(timingObj.page);
		//console.log(timingObj.branch);
		//console.log(timingObj.case);
		//console.log(timingObj.arranger);
		//console.log(timingObj.locale);
		//console.log(timingObj.region);
		//console.log(timingObj.elapsed);
		//alert('calling xhrpost');
				
                dojo.xhrPost ({
                // The page that parses the POST request
                url:'/index/addvastimingrecord',
                // Name of the Form we want to submit
                content: timingObj,
                // handle reply as JSON
                sync: true,
                handleAs: 'json',
                // Loads this function if everything went ok
                load: function (data) {
                        // Put the data into the appropriate <div>
                       //console.log(data);
	              // alert('got back: ' + data.status);
                },
                // Call this function if an error happened
                error: function (error) {
	                     //console.error('Error: ', error);
                             //alert(error);
                }
            }
        );
        
	}
</script>

<script language="JavaScript">
function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}
</script>

<?php
$keyInterceptor = "";
if ($this->currentVASpage == "FLORAL")
	$keyInterceptor = "onKeyPress='return disableEnterKey(event)'";
?>
</head>
<!-- REPLACED THIS... -->
<!--	onKeyPress='return disableEnterKey(event)'" -->
<!-- WITH THE FOLLOWING... -->
<body onload='<?php
echo $handlers?>' onunload='onunloadHandler();'
	<?php
	echo $keyInterceptor?>>

<script type="text/javascript">
//  dojo.require('dojo.parser');
//  dojo.require('dijit.form.DateTextBox');
//  dojo.require('dijit.form.TimeTextBox');
 </script>
<div id="container">

<div id="page">



	<?php
	if ($this->currentVASpage == "INTRO") {
		?>
	<div id="header">
<div id="headerimg"><img
	src="<?php
		echo FH_ART_BASE . "/" . $funeralHomeLogo?>"></div>
<div id="headerline"><img src="../art/every_step.gif"
	alt="We will be with you every step of the way."></div>
<br clear="all">
<div id="headertext">
<p><?php
		echo $funeralHomeName?>, <?php
		echo $funeralHomeAddr?>, <?php
		echo "$funeralHomeCity, $funeralHomeState $funeralHomeZip"?><br> Phone <?php
		echo "$funeralHomePhone"?></p>
</div>
</div>
	<?php
	} else {
		?>
	<div id="headerbase"><!--<div id="headerimg"><img src="<?php
		echo FH_ART_BASE . "/" . $funeralHomeLogo?>"></div>  height="154" width="186" -->
<div id="headerline"><img src="../art/every_step.gif"
	alt="We will be with you every step of the way."></div>
<br clear="all">
<div id="headertextbase">
<p><?php
		echo $funeralHomeName?>, <?php
		echo $funeralHomeAddr?>, <?php
		echo "$funeralHomeCity, $funeralHomeState $funeralHomeZip"?>&nbsp;&nbsp;&nbsp; Phone <?php
		echo "$funeralHomePhone"?></p>
</div>
<br>
</div>
<br clear="all">
	<?php
	}
	?>
	
	<?php
	if ($this->currentVASpage == "EXPECT" || $this->currentVASpage == "LIFE") {
		?>
	<br clear="all">
<form method="POST" id="vasform"
	action="<?php
		echo $this->moduleAction?>"><input type=hidden
	name="cartItems" id="cartItems" value="boo">
<div id="topbarsflash"><span id="maintitle"><?php
		echo $this->title?></span><span
	id="urlbar"><?php
		echo $urlBAR?></span></div>
<div id="contentflash"><br clear="all">
<div id="mainflash">
				<?php
		echo $this->layout ()->content;
		?><br clear="all">
<br>
				<?php
		echo $this->controls?>
			</div>
<br clear="all">
<img src="../art/footer_roundflash.jpg"></div>
</form>
	<?php
	} else {
		?>
	<br clear="all">
<form method="POST" id="vasform"
	action="<?php
		echo $this->moduleAction?>"><input type=hidden
	name="cartItems" id="cartItems" value="boo">
<div id="topbars"><span id="lefttitle">Menu</span><span id="maintitle"><?php
		echo $this->title?></span><span
	id="urlbar"><?php
		echo $urlBAR?></span></div>
<div id="content"><br clear="all">
<div id="leftnav">
<p><?php
		if (! $this->hide_breadcrumbs)
			echo $this->crumbs;
		?></p>
</div>
<div id="main"><!-- <span id="maintitle"><?php
		echo $this->title?></span> -->
				<?php
		echo $this->layout ()->content;
		?><br clear="all">
<br>
				<?php
		echo $this->controls?>
				<!-- <input type="submit" value=" Next " id="controlsnext"> --></div>
<br clear="all">
<img src="http://www.keymemsol.com/art/footer_round.jpg"></div>
</form>
	<?php
	}
	?>

<div id="footer">&copy; 2009 Key Memories</div>

</div>
<!-- end page -->
<div id="spacingfooter"><br>
<br>
</div>
</div>
<!-- end container -->

</body>
</html>
